﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;

namespace TuyennvLibrary.Notify.Android
{
    public class AndroidNotifyResponse : NotifyResponse
    {
        public List<string> RegistrationIds { get; set; }
        public List<string> RegistrationIdErrors { get; set; }
        public string Response { get; set; }
        public AndroidNotifyResponse()
            : base()
        {
            this.RegistrationIds = new List<string>();
            this.RegistrationIdErrors = new List<string>();
        }
        public AndroidNotifyResponse Analytics()
        {
            JObject json = JObject.Parse(Response);
            this.Success = (int)json["success"];
            this.Failure = (int)json["failure"];
            JArray jarrayResult = (JArray)json["results"];
            for (int i = 0; i < jarrayResult.Count; i++)
            {
                JObject obj = (JObject)jarrayResult[i];
                try
                {
                    string error = (string)obj["error"];
                    if (!string.IsNullOrEmpty(error))

                        RegistrationIdErrors.Add(RegistrationIds[i]);
                }
                catch (Exception)
                {
                }
            }
            return this;
        }

    }
}
